Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Jan 22, 2026

Preserve virtual-config parentage during flattening and prefer it during parent resolution so sibling routes like /posts and /posts/$id stay siblings

fixes #5822

Summary by CodeRabbit

  • New Features

    • Virtual routes can specify an explicit virtual parent so configured parent/child relationships are preserved instead of being auto-nested by path heuristics.
  • Tests

    • Added comprehensive test scenarios and generated route-tree snapshots covering virtual sibling routes and nested layouts with virtual routes to validate hierarchy and rendering.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

The PR records explicit virtual parent paths on route nodes during flattening and updates the generator to prefer those explicit parents when resolving parent-child relationships, preventing path-prefix auto-nesting for routes declared as siblings in virtual configs.

Changes

Cohort / File(s) Summary
Core Virtual Parent Implementation
packages/router-generator/src/filesystem/virtual/getRouteNodes.ts, packages/router-generator/src/generator.ts, packages/router-generator/src/types.ts
Add _virtualParentRoutePath?: string to RouteNode. flattenTree accepts/forwards parentRoutePath and sets _virtualParentRoutePath for non-root virtual children. generator.ts now resolves parents by honoring _virtualParentRoutePath (lookup in routeNodesByPath, fallback to prefixMap), preventing auto-nesting.
Tests & Generated Fixtures
packages/router-generator/tests/generator.test.ts, packages/router-generator/tests/generator/virtual-sibling-routes/*, packages/router-generator/tests/generator/virtual-nested-layouts-with-virtual-route/*
Add virtual-sibling-routes and virtual-nested-layouts-with-virtual-route test fixtures and snapshots. New route files (__root.tsx, layout.tsx, posts.tsx, post-detail.tsx, and nested layout routes) assert sibling relationships and complex virtual nesting behaviors in generated route trees.

Sequence Diagram(s)

sequenceDiagram
  participant Config as Virtual Config
  participant FS as getRouteNodes.flattenTree
  participant Generator as generator.handleNode
  participant Map as routeNodesByPath / prefixMap

  Config->>FS: produce virtual node tree
  FS->>FS: flattenTree(node, parentRoutePath)\nset node._virtualParentRoutePath (non-root)
  FS->>Generator: emit node list (with _virtualParentRoutePath)
  Generator->>Map: lookup node._virtualParentRoutePath in routeNodesByPath
  alt found in routeNodesByPath
    Map-->>Generator: parentRoute from routeNodesByPath
  else not found
    Map->>Map: fallback lookup via prefixMap
    Map-->>Generator: parentRoute from prefixMap
  end
  Generator->>Generator: assign node.parent and compute downstream paths
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • nlynzaad

Poem

🐰
I hop through nodes both near and far,
Marking parents where virtual routes are.
No surprise nesting where config has planned,
Siblings stay side-by-side, neat and grand. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(router-generator): respect explicit virtual route siblings' clearly and concisely describes the main change: fixing the router generator to respect explicitly configured sibling relationships in virtual routes configuration.
Linked Issues check ✅ Passed The PR implements the suggested fix from issue #5822: tracking explicit virtual parent relationships via _virtualParentRoutePath to prevent auto-nesting of routes like /posts and /posts/$id that are configured as siblings.
Out of Scope Changes check ✅ Passed All changes directly support the virtual route sibling relationship fix: core logic modifications (getRouteNodes.ts, generator.ts), type additions (types.ts), comprehensive test cases with route files and snapshots for both simple and nested scenarios.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 22, 2026

View your CI Pipeline Execution ↗ for commit b048734

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 10m 52s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 36s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-22 22:18:03 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 22, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6458

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6458

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6458

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6458

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6458

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6458

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6458

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6458

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6458

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6458

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6458

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6458

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6458

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6458

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6458

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6458

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6458

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6458

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6458

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6458

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6458

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6458

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6458

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6458

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6458

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6458

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6458

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6458

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6458

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6458

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6458

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6458

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6458

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6458

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6458

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6458

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6458

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6458

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6458

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6458

commit: b048734

@schiller-manuel schiller-manuel merged commit 70c81b3 into main Jan 22, 2026
6 checks passed
@schiller-manuel schiller-manuel deleted the fix-5822 branch January 22, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Virtual routes config doesn't respect explicit sibling relationships - auto-nests based on path matching

2 participants